package ${package}.web;

import java.net.UnknownHostException;

import com.zliov.inner.common.feign.FeignInterceptorConfig;
import com.zliov.inner.common.feign.GlobalFeignConfig;
import com.zliov.inner.common.login.ILoginUserService;
import com.zliov.inner.common.login.LoginUserFeignImpl;
import com.zliov.inner.common.login.OAuthFeign;
import com.zliov.inner.log.annotation.EnableLogging;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.net.InetAddress;
import java.net.UnknownHostException;

@EnableAsync
@Configuration
@EnableDiscoveryClient
@EnableScheduling
@EnableLogging
@EnableTransactionManagement
@SpringBootApplication(scanBasePackages = {"${package}"},exclude = {DataSourceAutoConfiguration.class})
@EnableFeignClients(basePackageClasses = {OAuthFeign.class}, defaultConfiguration = {GlobalFeignConfig.class, FeignInterceptorConfig.class}, basePackages = {"com.zliov.**"})
@MapperScan(value = {"${package}.domain.mapper","com.zliov.**.dao"})
public class Application {
    static Logger logger = LoggerFactory.getLogger(Application.class);

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(Application.class, args);
        Environment env = application.getEnvironment();
        String address = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        logger.info("\n----------------------------------------------------------\n\t" +
                        "Application '{}' is running! Access URLs:\n\t" +
                        "Local: \t\thttp://localhost:{}\n\t" +
                        "External: \thttp://{}:{}\n\t" +
                        "Doc: \thttp://{}:{}/doc.html\n" +
                        "----------------------------------------------------------",
                env.getProperty("spring.application.name"),
                port,
                address,
                port,
                address,
                port);
    }
}
